package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNeedpullData;
import com.ruoyi.system.service.ISysNeedpullDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源同步Controller
 * 
 * @author ruoyi
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/system/data")
public class SysNeedpullDataController extends BaseController
{
    @Autowired
    private ISysNeedpullDataService sysNeedpullDataService;

    /**
     * 查询资源同步列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNeedpullData sysNeedpullData)
    {
        startPage();
        List<SysNeedpullData> list = sysNeedpullDataService.selectSysNeedpullDataList(sysNeedpullData);
        return getDataTable(list);
    }

    /**
     * 导出资源同步列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "资源同步", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysNeedpullData sysNeedpullData)
    {
        List<SysNeedpullData> list = sysNeedpullDataService.selectSysNeedpullDataList(sysNeedpullData);
        ExcelUtil<SysNeedpullData> util = new ExcelUtil<SysNeedpullData>(SysNeedpullData.class);
        util.exportExcel(response, list, "资源同步数据");
    }

    /**
     * 获取资源同步详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysNeedpullDataService.selectSysNeedpullDataById(id));
    }

    /**
     * 新增资源同步
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "资源同步", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNeedpullData sysNeedpullData)
    {
        return toAjax(sysNeedpullDataService.insertSysNeedpullData(sysNeedpullData));
    }

    /**
     * 修改资源同步
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "资源同步", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNeedpullData sysNeedpullData)
    {
        return toAjax(sysNeedpullDataService.updateSysNeedpullData(sysNeedpullData));
    }

    /**
     * 删除资源同步
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "资源同步", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysNeedpullDataService.deleteSysNeedpullDataByIds(ids));
    }
}
